/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Replication code for "Institutional Constraints on the Executive, Investment, and Elections"
//
// The code in this file replicates all analyses included in the article and the tables in the online supplemental materials, with the exception of 
// analyses discussed in footnote 15 (those can be replicated using the replication code file "footnote15_analysis.do"). 
// The code in this file uses the data set: "main_analyses_and_supplemental_tables.dta"
//
// Additional notes for replicating the results:
// Please note that in Table 3, the row labels for "Executive election × Lagged %urban" and "Lagged % urban" are mistakenly reversed in the article table (but not the description of the results in the text).
// Additionally, please note the following minor errors in standard error values shown in the tables of the article, none of which affect any substantive
// claims or claims about significance levels in the text:
// Table 1, Column 2: The standard error for the "Executive Election variable" coefficient is 8.00, not 7.80.
// Table 1, Column 4: The standard error for the "Executive Election variable" coefficient is 5.66, not 5.67.
// Table 3, Column 4: The standard error for "Executive Election x lagged % Urban" is 0.10, not 0.14.
// Table 4, Column 3: The standard error for "Executive Election x Institutional Constraints" is 15.15, not 15.17.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

clear
ssc install estout, replace
ssc install ftools, replace
ssc install reghdfe, replace
ssc install xtscc, replace
ssc install interflex, replace all


global path="" //directory where datasets for analysis should be located
cd $path //set main folder directory as working directory

//if it does not already exist, create a "working data" folder in working directory
capture confirm file "./working data/"
if _rc mkdir "./working data/"

capture log close
capture log using "./working data/main_analyses_and_supplemental_tables.log", replace
set more off

clear
use "main_analyses_and_supplemental_tables.dta" 

////////////////////////////////////////////////////
// Figure 1. Average Private Fixed Investment Growth
////////////////////////////////////////////////////
sort countryname year

by countryname: gen lgelt=elt[_n-1] if  main_sample==1 
by countryname: gen f1elt=elt[_n+1] if   main_sample==1 
by countryname: gen f2elt=elt[_n+2] if   main_sample==1 

replace lgelt=. if elt==1 & lgelt==1
replace f1elt=. if elt==1 & f1elt==1
replace f2elt=. if elt==1 & f2elt==1

egen meanpfielt=mean(chrprivgfcf100_w005e) if  main_sample==1  & elt==1

egen meanpfilgelt=mean(chrprivgfcf100_w005e) if main_sample==1 & lgelt==1

egen meanpfif1elt=mean(chrprivgfcf100_w005e) if  main_sample==1  & f1elt==1

egen meanpfif2elt=mean(chrprivgfcf100_w005e) if main_sample==1  & f2elt==1

sum meanpfilgelt meanpfielt meanpfif1elt meanpfif2elt

keep if main_sample==1
gen id_check2=_n
keep if id_check2<5
 
keep meanpfif2elt meanpfif1elt meanpfielt meanpfilgelt id_check2

gen yvalues=.
replace yvalues=meanpfif2elt[2] if id_check2==1
replace yvalues=meanpfif1elt[3] if id_check2==2 
replace yvalues=meanpfielt[4] if id_check2==3
replace yvalues=meanpfilgelt[1] if id_check2==4
line yvalues id_check2, yscale(range(0 14)) ylabel(0 "0%" 2 "2%" 4 "4%" 6 "6%" 8 "8%" 10 "10%" 12 "12%" 14 "14%", angle(0)) xlabel(1 "Y-2" 2 "Y-1" 3 "Executive Election (Y)" 4 "Y+1") ytitle("") title("") xtitle("")
////////////////////

clear
eststo clear
use "main_analyses_and_supplemental_tables.dta" 

//////////////////////////////////////////////////////////////////////////////////////
// Table 1. Institutional Constraints on the Executive and Electoral Investment Cycles
//////////////////////////////////////////////////////////////////////////////////////

* (1) Pooled OLS
eststo: reg chrprivgfcf100_w005e  elt  chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e if main_sample==1, robust

* (2) Pooled OLS
eststo: reg chrprivgfcf100_w005e  elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e if  main_sample==1, robust

* (3) PCSE
eststo: xtpcse chrprivgfcf100_w005e  elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

testparm i.countryid 
testparm i.year
testparm i.countryid i.year

* (4) PCSE
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.countryid i.year if main_sample==1, hetonly corr(ar1)

testparm i.countryid 
testparm i.year
testparm i.countryid i.year

* (5) PSCE
eststo: xtpcse chrprivgfcf100_w005e lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (6) Two-way Clustered SEs
eststo: reghdfe chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e if main_sample==1, absorb(countryid year) cluster(countryid year)

* (7) Driscoll-Kraay
eststo: xtscc chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e i.year if main_sample==1, fe

* (8) PSCE, Interest Rate
eststo: xtpcse chrprivgfcf100_w005e  elt eltlnpolconv lnpolconv chrealinterest_w005e chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1) 

esttab using "./working data/Table 1.rtf", title("Table 1. Institutional Constraints on the Executive and Electoral Investment Cycles") mtitles("Pooled OLS" "Pooled OLS" "PSCE" "PSCE" "PSCE" "Two-way slustered SEs" "Driscoll-Kraay" "PSCE, Interest Rate")  se(a) label  nogap onecell compress  keep(elt eltlnpolconv lnpolconv eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e  chrealinterest_w005e) order(elt eltlnpolconv lnpolconv eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt  chcpi_w005e chrealinterest_w005e) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

/////////////////////////////////////////////////////////////
// Table 2. Alternative Measures of Institutional Constraints
/////////////////////////////////////////////////////////////

* (1) ln XCONST
eststo: xtpcse chrprivgfcf100_w005e elt eltlnxconst lnxconst chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year  if main_sample==1, hetonly corr(ar1)

* (2) Linear XCONST
eststo: xtpcse chrprivgfcf100_w005e elt eltxconst xconst chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year  if main_sample==1, hetonly corr(ar1)

* (3) ln Liberal Component Index
eststo: xtpcse chrprivgfcf100_w005e elt eltlnv2xlib lnv2xlib chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year  if  main_sample==1, hetonly corr(ar1)

* (4) Linear Liberal Component Index
eststo: xtpcse chrprivgfcf100_w005e elt eltv2xlib v2x_liberal chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year  if main_sample==1, hetonly corr(ar1)

esttab using "./working data/Table 2.rtf", title("Table 2. Alternative Measures of Institutional Constraints") mtitles("ln XCONST" "Linear XCONST)" "ln Liberal Component Index" "Linear Liberal Component Index")  se(a) label  nogap onecell compress  keep(elt lnxconst xconst eltlnxconst eltxconst   eltlnv2xlib lnv2xlib eltv2xlib  v2x_liberal chlgrealpcgdpUS_w005e chcpi_w005e regimedum4 regimedum3 regimedum2  rpt_for_elt    ) order(elt eltlnxconst lnxconst eltxconst  xconst eltlnv2xlib lnv2xlib eltv2xlib  v2x_liberal     chlgrealpcgdpUS_w005e    regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2)

eststo clear
////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Calculate standard deviations for alternative measures of institutional constraints within main sample
/////////////////////////////////////////////////////////////////////////////////////////////////////////
clear
use "main_analyses_and_supplemental_tables.dta" 


collapse (sd) polconv lnpolconv xconst lnxconst v2x_liberal lnv2xlib if main_sample==1 , by(countryname)

sum polconv lnpolconv xconst lnxconst v2x_liberal lnv2xlib,d 


//////////////////////////////////////////////////////////////
// Table 3. Endogenous Political Institutions and Urbanization
//////////////////////////////////////////////////////////////
clear
use "main_analyses_and_supplemental_tables.dta" 

eststo clear

* (1) Pooled OLS
eststo: reg chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e   regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e if  main_sample==1& colony==1 &englishlaw!=.&  lpd1500s!=., robust

* (2) Pooled OLS
eststo: reg chrprivgfcf100_w005e elt eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e if  main_sample==1& colony==1 &englishlaw!=.&  lpd1500s!=., robust

* (3) 2SLS 2nd Stage
eststo: ivregress 2sls chrprivgfcf100_w005e elt  (eltlnpolconv lnpolconv =englishlaw eltenglish lpd1500s eltlpd1500s) lgurbanpct lgurbanpctelt  chlgrealpcgdpUS_w005e   regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year i.regionid if  main_sample==1& colony==1 &englishlaw!=.&  lpd1500s!=., robust

* (4) 2SLS 2nd Stage
eststo: ivregress 2sls chrprivgfcf100_w005e elt  (eltpolconv polconv =englishlaw eltenglish lpd1500s eltlpd1500s) lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year i.regionid if  main_sample==1& colony==1 &englishlaw!=.&  lpd1500s!=., robust

// N.B. additional ivregress results are in supplemental_analysis.do file

* (5) PSCE
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year i.countryid if main_sample==1, hetonly corr(ar1)

* (6) PSCE
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year i.countryid if  main_sample==1, hetonly corr(ar1)

esttab using "./working data/Table 3.rtf", title("Table 3. Endogenous Political Institutions and Urbanization") mtitles( "Pooled OLS" "Pooled OLS" "2SLS 2nd Stage" "2SLS 2nd Stage" "PSCE" "PSCE")  se(a) label  nogap onecell compress  keep(elt eltlnpolconv lnpolconv eltpolconv polconv lgurbanpct lgurbanpctelt  chlgrealpcgdpUS_w005e regimedum4 regimedum3 regimedum2  rpt_for_elt  chcpi_w005e ) order(elt  eltlnpolconv lnpolconv eltpolconv polconv  lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e  regimedum4 regimedum3 regimedum2  rpt_for_elt  chcpi_w005e) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2)

eststo clear
////////////////////

/////////////////////////////////////////////////////
// Table 4. Presidential Systems with Fixed Elections
/////////////////////////////////////////////////////

* (1) President-Fixed
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year  if  pfix1_sample==1 & president_fixed==1,hetonly corr(ar1)

* (2) Disc.
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year  if pfix0_sample==1 & president_fixed==0,hetonly corr(ar1)

* (3) President-Fixed
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if  pfix1_sample==1 & president_fixed==1,hetonly corr(ar1)

* (4) Disc.
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if pfix0_sample==1 & president_fixed==0, hetonly corr(ar1)

* (5) President-Fixed
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year  if  pfix1_sample==1 & president_fixed==1,hetonly corr(ar1)

* (6) Disc.
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year  if pfix0_sample==1 & president_fixed==0,hetonly corr(ar1)

esttab using "./working data/Table 4.rtf", title("Table 4. Presidential Systems with Fixed Elections") mtitles( "President-Fixed"  "Disc." "President-Fixed" "Disc." "President-Fixed" "Disc.")  se(a) label  nogap onecell compress keep(elt eltlnpolconv lnpolconv polconv eltpolconv  chlgrealpcgdpUS_w005e  regimedum4 regimedum3 regimedum2 rpt_for_elt  chcpi_w005e ) order(elt eltlnpolconv lnpolconv eltpolconv polconv  chlgrealpcgdpUS_w005e  regimedum4 regimedum3 regimedum2 rpt_for_elt  chcpi_w005e) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2)

eststo clear


/////////////////////////////////////////////
/// Appendix Table A2. Descriptive Statistics
////////////////////////////////////////////

sum chrprivgfcf100_w005e chrprivgfcf100 elt polconv lnpolconv xconst lnxconst v2x_liberal lnv2xlib chlgrealpcgdpUS_w005e chlgrealpcgdpUS chcpi_w005e chcpi chrealinterest_w005e chrealinterest regimedum4 regimedum3 regimedum2 regimedum1 rpt_for_elt lgurbanpct if main_sample==1
sum englishlaw lpd1500s if main_sample==1 & colony==1 &lpd1500s!=. &englishlaw!=.


/////////////////////////////////////////////////////////////////////////////////////////////////////
// The below code replicates all supplemental analyses included in the online supplemental materials.
/////////////////////////////////////////////////////////////////////////////////////////////////////

clear
eststo clear

use "main_analyses_and_supplemental_tables.dta" 

///////////////////////////////////////////////////////////////////
// Supplemental Table S1. Alternative Executive Election Indicators
///////////////////////////////////////////////////////////////////

* (1) Half-years
eststo: xtpcse chrprivgfcf100_w005e e1 e2 e1lnpolconv e2lnpolconv lnpolconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt2 chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (2) Half-years
eststo: xtpcse chrprivgfcf100_w005e e1 e2 e1polconv e2polconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt2 chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (3) Calendar year
eststo: xtpcse chrprivgfcf100_w005e calelecyr calelecyrlnpolconv lnpolconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt2 chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (4) Calendar year
eststo: xtpcse chrprivgfcf100_w005e calelecyr calelecyrpolconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt2 chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

esttab using "./working data/Table S1.rtf", title("Supplemental Table S1. Alternative Executive Election Indicators") mtitles("Half-years" "Half-years" "Calendar year" "Calendar year")  se(a) label  nogap onecell compress  keep(e1 e2 calelecyr e1lnpolconv e2lnpolconv  e1polconv e2polconv calelecyrlnpolconv lnpolconv calelecyrpolconv polconv   ) order(e2 e1 e2lnpolconv  e1lnpolconv e2polconv  e1polconv  calelecyr calelecyrlnpolconv calelecyrpolconv lnpolconv polconv  ) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

// Table to output coefficient estimates and standard errors for control variables:
//esttab using "./working data/Table S1b.rtf", title("Supplemental Table S1. Alternative Executive Election Indicators, Control Variables") mtitles("Half-years" "Half-years" "Calendar year" "Calendar year")  se(a) label  nogap onecell compress  keep( chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt2 chcpi_w005e  ) order(chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt2 chcpi_w005e ) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

///////////////////////////////////////////////////////////////////////
// Supplemental Table S2. Alternative Combinations of Control Variables
///////////////////////////////////////////////////////////////////////

* (1) Region-Year effects
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year##i.regionid if main_sample==1, hetonly corr(ar1)

* (2) Region-Year effects
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv  chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year##i.regionid if main_sample==1, hetonly corr(ar1)

* (3) Excluding ideology controls
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (4) Excluding ideology controls
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv  chlgrealpcgdpUS_w005e chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

esttab using "./working data/Table S2.rtf", title("Supplemental Table S2. Alternative Combinations of Control Variables") mtitles("Region-Year Effects" "Region-Year Effects" "Excluding ideology controls" "Excluding ideology controls")  se(a) label  nogap onecell compress  keep(elt eltlnpolconv lnpolconv eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e) order(elt eltlnpolconv lnpolconv eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

/////////////////////////////////////////////////////////////////////////
// Supplemental Table S3. Alternative Approaches to Outlying Observations
/////////////////////////////////////////////////////////////////////////

* (1) ln(x+min x)
eststo: xtpcse lngrowth elt eltlnpolconv lnpolconv lnchlgrealpcgdpUS  regimedum2 regimedum3 regimedum4 rpt_for_elt lnchcpi i.countryid i.year if main_sample==1, hetonly corr(ar1)  

* (2) ln(x+min x)
eststo: xtpcse lngrowth elt eltpolconv polconv  lnchlgrealpcgdpUS  regimedum2 regimedum3 regimedum4 rpt_for_elt lnchcpi i.countryid i.year if main_sample==1, hetonly corr(ar1)  

* (3) IHS
eststo: xtpcse lngrowthIHS elt eltlnpolconv lnpolconv lnchlgrealpcgdpUSIHS  regimedum2 regimedum3 regimedum4 rpt_for_elt lnchcpiIHS i.countryid i.year if main_sample==1, hetonly corr(ar1)  

* (4) IHS
eststo: xtpcse lngrowthIHS elt eltpolconv polconv  lnchlgrealpcgdpUSIHS  regimedum2 regimedum3 regimedum4 rpt_for_elt lnchcpiIHS i.countryid i.year if main_sample==1, hetonly corr(ar1)  

* Prepare first regression with outliers removed
reg chrprivgfcf100_w005e elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1
//lvr2plot, mlabel(obs_id) msize(tiny) mlabsize(tiny)

predict resid, residuals 
predict leverage, leverage
gen resid2=resid^2
egen maxresid2=max(resid2)
egen minresid2=min(resid2)
gen nsresid2=(resid2-minresid2)/(maxresid2-minresid2)

gen excl_hloo1=1 if nsresid2>0.1 & e(sample) & leverage >0.1

* (5) Outliers removed
eststo: xtpcse chrprivgfcf100_w005e  elt eltlnpolconv lnpolconv chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1 &excl_hloo1!=1, hetonly corr(ar1)

drop resid
drop leverage
drop resid2
drop maxresid2
drop minresid2
drop nsresid2

* Prepare first regression with outliers removed
reg chrprivgfcf100_w005e elt eltpolconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1
//lvr2plot, mlabel(obs_id) msize(tiny) mlabsize(tiny)
 
predict resid, residuals 
predict leverage, leverage
gen resid2=resid^2
egen maxresid2=max(resid2)
egen minresid2=min(resid2)
gen nsresid2=(resid2-minresid2)/(maxresid2-minresid2)

gen excl_hloo2=1 if nsresid2>0.1 & e(sample) & leverage >0.1

* (6) Outliers removed 
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1 &excl_hloo2!=1, hetonly corr(ar1)

esttab using "./working data/Table S3.rtf", title("Table S3. Alternative Approaches to Outlying Observations") mtitles( "ln(x+min x)"  "ln(x+min x)" "IHS"  "IHS" "Outliers Removed" "Outliers Removed")  se(a) label  nogap onecell compress  keep( elt eltlnpolconv eltpolconv lnpolconv polconv  ) order( elt eltlnpolconv lnpolconv eltpolconv polconv ) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

// Table to output coefficient estimates and standard errors for control variables:
//esttab using "./working data/Table S3b.rtf", title("Table S3b. Alternative Approaches to Outlying Observations, Control Variables") mtitles( "ln(x+min x)"  "ln(x+min x)" "IHS"  "IHS" "Outliers Removed" "Outliers Removed")  se(a) label  nogap onecell compress  keep(chlgrealpcgdpUS_w005e lnchlgrealpcgdpUS  lnchlgrealpcgdpUSIHS regimedum4 regimedum3 regimedum2  rpt_for_elt chcpi_w005e lnchcpi lnchcpiIHS) order(chlgrealpcgdpUS_w005e lnchlgrealpcgdpUS  lnchlgrealpcgdpUSIHS regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e lnchcpi lnchcpiIHS) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

/////////////////////////////////////////////////////////////////////////////
//Supplemental Table S4.  Controlling for Electoral Democracy, Main Variables
/////////////////////////////////////////////////////////////////////////////

* (1) Free & fair elections
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv eltlnv2xelfrefair lnv2xelfrefair chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (2) ML Democracy
eststo: xtpcse chrprivgfcf100_w005e elt eltlnpolconv lnpolconv eltlncmldi lncmldi chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (3) Free & fair elections
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv eltv2xelfrefair v2xel_frefair chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

* (4) ML Democracy
eststo: xtpcse chrprivgfcf100_w005e elt eltpolconv polconv eltcmldi c_mldi chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.countryid i.year if main_sample==1, hetonly corr(ar1)

esttab using "./working data/Table S4.rtf", title("Table S4. Controlling for Electoral Democracy, Main Variables") mtitles("Free & fair elections" "ML Democracy" "Free & fair elections" "ML Democracy" )  se(a) label  nogap onecell compress  keep(elt eltlnpolconv lnpolconv eltlnv2xelfrefair lnv2xelfrefair eltlncmldi lncmldi eltpolconv polconv eltv2xelfrefair v2xel_frefair eltcmldi c_mldi ) order(elt eltlnpolconv lnpolconv eltlnv2xelfrefair lnv2xelfrefair eltlncmldi lncmldi eltpolconv polconv eltv2xelfrefair v2xel_frefair eltcmldi c_mldi ) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

// Table to output coefficient estimates and standard errors for control variables:
//esttab using "./working data/Table S4b.rtf", title("Table S4b. Controlling for Electoral Democracy, Control Variables") mtitles("Free & fair elections" "ML Democracy" "Free & fair elections" "ML Democracy" )  se(a) label  nogap onecell compress  keep( chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e  ) order(chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e ) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

///////////////////////////////////////////////////////////////////////////
//Supplemental Table S5. Supplental Control Variable Estimates for Table 2 
///////////////////////////////////////////////////////////////////////////

* Supplemental Table S5 shows estimates and corresponding standard errors for control variables for analyses shown in Table 2.
* Please run commands under heading "Table 2. Alternative Measures of Institutional Constraints" for results in table.


///////////////////////////////////////////////////////////////////////////////////
// Supplemental Table S6. Alternative Specifications for ln Liberal Component Index
///////////////////////////////////////////////////////////////////////////////////

* (1) Driscoll-Kraay standard errors
eststo: xtscc chrprivgfcf100_w005e elt eltlnv2xlib lnv2xlib chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year if main_sample==1, fe

* (2) Two-way clustered standard errors
eststo: reghdfe chrprivgfcf100_w005e elt eltlnv2xlib lnv2xlib chlgrealpcgdpUS_w005e  regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e if main_sample==1, absorb(countryid year) cluster(countryid year)

esttab using "./working data/Table S6.rtf", title("Table S6. Alternative Specifications for ln Liberal Component Index") mtitles("Driscoll-Kraay standard errors" "Two-way clustered standard errors")  se(a) label  nogap onecell compress  keep(elt eltlnv2xlib lnv2xlib chlgrealpcgdpUS_w005e  regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e) order(elt eltlnv2xlib lnv2xlib chlgrealpcgdpUS_w005e  regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////
// Supplemental Table S7. First-Stage Estimates from 2SLS Analysis of Endogenous Institutions
/////////////////////////////////////////////////////////////////////////////////////////////

* 1st-stage estimates Column 3 of Table 3
* (1) ln Institutional constraints
* (2) Executive Election x ln Institutional constraints

ivregress 2sls chrprivgfcf100_w005e elt  (eltlnpolconv lnpolconv =englishlaw eltenglish lpd1500s eltlpd1500s) lgurbanpct lgurbanpctelt  chlgrealpcgdpUS_w005e   regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year i.regionid if main_sample==1 & colony==1, first robust

reg lnpolconv elt lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e i.year i.regionid englishlaw eltenglish lpd1500s eltlpd1500s if main_sample==1 & colony==1, robust

test englishlaw  eltenglish lpd1500s  eltlpd1500s

reg eltlnpolconv elt lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e i.year i.regionid englishlaw eltenglish lpd1500s eltlpd1500s if main_sample==1 & colony==1, robust

test englishlaw  eltenglish lpd1500s  eltlpd1500s

* 1st-stage estimates Column 4 of Table 3
* (1) Institutional constraints
* (2) Executive Election x Institutional constraints

ivregress 2sls chrprivgfcf100_w005e elt  (eltpolconv polconv =englishlaw eltenglish lpd1500s eltlpd1500s) lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year i.regionid if main_sample==1 & colony==1, first robust 

reg eltpolconv elt lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e i.year i.regionid englishlaw eltenglish lpd1500s eltlpd1500s if main_sample==1 & colony==1, robust
test englishlaw  eltenglish lpd1500s  eltlpd1500s

reg polconv elt lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4  rpt_for_elt chcpi_w005e i.year i.regionid englishlaw eltenglish lpd1500s eltlpd1500s if main_sample==1 & colony==1, robust
test englishlaw  eltenglish lpd1500s  eltlpd1500s

eststo clear
////////////////////

////////////////////////////////////////////////////////
// Results for Additional Notes on Supplemental Table S7
////////////////////////////////////////////////////////

ivregress 2sls chrprivgfcf100_w005e elt  (eltlnpolconv lnpolconv =englishlaw eltenglish lpd1500s eltlpd1500s) lgurbanpct lgurbanpctelt  chlgrealpcgdpUS_w005e   regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year i.regionid if main_sample==1 & colony==1, first robust
estat endogenous
estat firststage ,all
estat overid

ivregress 2sls chrprivgfcf100_w005e elt  (eltpolconv polconv =englishlaw eltenglish lpd1500s eltlpd1500s) lgurbanpct lgurbanpctelt chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year i.regionid if main_sample==1 & colony==1, first robust
estat endogenous
estat firststage ,all
estat overid
////////////////////

///////////////////////////////////////////////////////////////////////////
//Supplemental Table S8. Estimates for 2nd-stage Control Variables, Table 3
///////////////////////////////////////////////////////////////////////////

* Supplemental Table S8 shows estimates and corresponding standard errors for control variables for analyses shown in Table 3.
* Please run commands under heading "Table 3. Endogenous Political Institutions and Urbanization" for results in table.


////////////////////////////////////////////////////////////////
//Supplemental Table S9. Control Variable Estimates for Table 4
////////////////////////////////////////////////////////////////

* Supplemental Table S9 shows estimates and corresponding standard errors for control variables for analyses shown in Table 4.
* Please run commands under heading "Table 4. Presidential Systems with Fixed Elections" for results in table.


///////////////////////////////////////////////////////////////////////////////////////////
// Supplemental Table S10, Panel A. Endogenous Discretionary Elections, 2nd-stage Estimates
///////////////////////////////////////////////////////////////////////////////////////////

* (1) ln Institutional Constraints
eststo: ivregress 2sls chrprivgfcf100_w005e (elt eltlnpolconv =termover termoverlnpolconv) lnpolconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year i.countryid if pfix0_sample==1 & president_fixed==0, robust

* (2) Linear Institutional Constraints
eststo: ivregress 2sls chrprivgfcf100_w005e (elt eltpolconv =termover termoverpolconv) polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year i.countryid if  pfix0_sample==1 & president_fixed==0, robust

esttab using "./working data/Table S10A.rtf", title("Supplemental Table S10, Panel A. Endogenous Discretionary Elections, 2nd-stage Estimates") mtitles("ln Institutional Constraints" "Linear Institutional Constraints")  se(a) label  nogap onecell compress  keep(elt eltlnpolconv lnpolconv eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt chcpi_w005e  ) order(elt eltlnpolconv lnpolconv eltpolconv polconv chlgrealpcgdpUS_w005e   regimedum4 regimedum3 regimedum2 rpt_for_elt  chcpi_w005e ) star(* 0.10 ** 0.05 *** 0.01) replace unstack b(2) 

eststo clear
////////////////////

///////////////////////////////////////////////////////////////////////////////////////////
// Supplemental Table S10, Panel B. Endogenous Discretionary Elections, 1st-stage Estimates
///////////////////////////////////////////////////////////////////////////////////////////

* ln Institutional Constraints
ivregress 2sls chrprivgfcf100_w005e (elt eltlnpolconv =termover termoverlnpolconv) lnpolconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  i.year i.countryid if pfix0_sample==1 & president_fixed==0, robust first
estat endogenous
estat firststage ,all

* Linear Institutional Constraints
ivregress 2sls chrprivgfcf100_w005e (elt eltpolconv =termover termoverpolconv) polconv chlgrealpcgdpUS_w005e regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e i.year i.countryid if pfix0_sample==1 & president_fixed==0, robust first
estat endogenous
estat firststage ,all
////////////////////

////////////////////////////////////////////////////////////////////////////////
*Supplemental Figure 1: Linear Interaction Effect and Common Support Assumptions
////////////////////////////////////////////////////////////////////////////////

interflex chrprivgfcf100 elt polconv  chlgrealpcgdpUS_w005e   regimedum2 regimedum3 regimedum4 rpt_for_elt chcpi_w005e  if  main_sample==1, fe (countryname year) cluster(countryname) vce(robust) dlabel("Executive Election") xlabel("Institutional Constraints") ylabel("Private Fixed Investment Growth") xd(density) 
//N.B. To reproduce the labels of Supplemental Figure 1, manually change size of axis labels to "v. Small" ; the size of the labels to "Small", and add zeroes to x-axis values .2, .4, .6, and .8 in the Graph Editor

log close














